/**
 * 
 */
package com.ubo.java.model.methode;

import java.util.Set;


import com.ubo.java.model.EModifier;
import com.ubo.java.model.EVisibility;
import com.ubo.java.model.IType;
import com.ubo.java.model.classifier.ClassModel;
import com.ubo.java.model.comment.Comment;
import com.ubo.java.model.declaration.Parameter;
import com.ubo.transform.java.IJavaVisitor;

/**
 * @author saludegu
 * 
 */
public class Method extends ASignature {

	/**
	 * Nom de la méthode.
	 */
	protected String mMethodName;

	/**
	 * Liste des exceptions lancées par la méthode.
	 */
	protected Set<ClassModel> mListClassThrowns;

	/**
	 * Liste des modifiers.
	 */
	protected Set<EModifier> mModifierList;

	/**
	 * Indique si cette methode est overridé ou non.
	 */
	protected final boolean mOverrided;

	/**
	 * 
	 * Constructor
	 * 
	 * @param methodName
	 * @param modifierList
	 * @param visibility
	 * @param exceptionList
	 */
	public Method(String methodName, Set<EModifier> modifierList,
			EVisibility visibility, Set<ClassModel> exceptionList,
			Set<Parameter> parameters, IType type, boolean overrided) {
		super(visibility, parameters, type);
		mMethodName = methodName;
		mListClassThrowns = exceptionList;
		mModifierList = modifierList;
		mOverrided = overrided;
		mComment = new Comment(new StringBuffer("\t*\n\t"));
		generateComments();
		if (mListClassThrowns != null && mListClassThrowns.size() > 0) {
			for (ClassModel classModel : mListClassThrowns) {
				mComment.addException(classModel.printPath());
			}
		}
		if (mOverrided && mModifierList.contains(EModifier.ABSTRACT))
			mModifierList.remove(EModifier.ABSTRACT);
	}

	/**
	 * 
	 * Constructor
	 * 
	 * @param methodName
	 * @param modifierList
	 * @param visibility
	 * @param exceptionList
	 */
	public Method(String methodName, Set<EModifier> modifierList,
			EVisibility visibility, Set<ClassModel> exceptionList,
			Set<Parameter> parameters, IType type, boolean overrided,
			Comment newComment) {
		super(visibility, parameters, type);
		mMethodName = methodName;
		mListClassThrowns = exceptionList;
		mModifierList = modifierList;
		mComment = newComment;
		mOverrided = overrided;
		if (mOverrided && mModifierList.contains(EModifier.ABSTRACT))
			mModifierList.remove(EModifier.ABSTRACT);
	}

	/**
	 * Indique si la méthode est overridée ou non.
	 * 
	 * @return
	 */
	public boolean isOverrided() {
		return mOverrided;
	}

	/**
	 * @see com.ubo.transform.java.IJavaGenerable#generate(com.ubo.transform.java.IJavaVisitor)
	 */
	@Override
	public void generate(IJavaVisitor<?> generator) {
		generator.generate(this);
	}

	/**
	 * @return the mMethodName
	 */
	public String getMethodName() {
		return mMethodName;
	}

	/**
	 * @return the mListClassThrowns
	 */
	public Set<ClassModel> getListClassThrowns() {
		return mListClassThrowns;
	}

	/**
	 * @return the mModifierList
	 */
	public Set<EModifier> getModifierList() {
		return mModifierList;
	}
}
